package com.wdc.test;

public class 数字2出现的次数 {

    public static int ca(int n) {


        int count = 0;

        for (int i = 0; i <= n; i++) {
            String value = String.valueOf(i);
            char[] charArray = value.toCharArray();
            for (int j = 0; j < value.length(); j++) {
                if (charArray[j] == '2') {
                    count++;
                }
            }


        }

        return count;
    }


    public static void main(String[] args) {

        int a = 25;
        System.out.println(ca(a));

    }

}
